package com.sc.byahi.user.server;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

import com.sc.byahi.user.shared.Profile;
import com.sc.byahi.user.shared.constants.Lists;

public class TestProfileCreator {
	List<Profile> createTestProfiles(String gender, String data) {
		readXML();
		List<Profile> p = readProfiledata(gender, data);
		// Now work is finished, remove junk data
		ConstantsManager.getInstance().getLists().remove(Lists.CITIES);
		return p;
	}

	private List<Profile> readProfiledata(String gender, String data) {
		List<Profile> profiles = new ArrayList<Profile>();
		try {
			// File file = new File(".");
			// System.out.println(file.getAbsolutePath());
			// InputStream is = this.getClass().getResourceAsStream("profiles.csv");

			BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(data.getBytes())));
			String profile = null;
			while ((profile = br.readLine()) != null) {
				String name = profile.trim();
				final Profile p = new Profile();
				p.setApproved(true);
				Calendar c = Calendar.getInstance();
				c.set(Calendar.YEAR, 1991);
				Date min = c.getTime();
				c.set(Calendar.YEAR, 1981);
				Date max = c.getTime();
				Long range = min.getTime() - max.getTime();
				long dob = (long) (range * Math.random()) + max.getTime();
				c.setTimeInMillis(dob);
				p.setDob(c.getTime());
				p.setName(name);
				// String[] owner = name.split(" ");
				String email = "";
				if ("Female".equals(gender)) {
					email = "female@byahi.com";
				} else {
					email = "male@byahi.com";
				}

				p.setOwner(email);
				p.setOwnerAgency(Boolean.TRUE);
				p.setGender(gender);
				p.setBloodGroup(pickRandomFromList(Lists.BLOOD_GROUP, 1, null).get(0));
				p.setReligion(pickRandomFromList(Lists.RELIGIONS, 1, null).get(0));
				p.setCaste(pickRandomFromList(Lists.CASTE, 1, p.getReligion()).get(0));
				p.setDegrees(pickRandomFromList(Lists.DEGREES, 3, null));
				// p.setDrinking(randBool());
				// p.setDriving(randBool());
				p.setEatingHabits(pickRandomFromList(Lists.DIET, 1, null).get(0));
				p.setEmploymentType(pickRandomFromList(Lists.EMPLOYMENT_TYPE, 1, null).get(0));
				Long in = ftInStringToInches(pickRandomFromList(Lists.HEIGHT_FT, 1, null).get(0));
				p.setHeight(in);
				p.setLanguages(pickRandomFromList(Lists.MOTHER_TONGUE, 3, null));
				p.setManglik(randBool());
				String m = pickRandomFromList(Lists.MARITAL_STATUS, 1, null).get(0);
				p.setMaritalStatus(m);
				if (!"Unmarried".equals(m)) {
					// p.setMaritalStatusDetail(randString());
					p.setMaritalStatusChildren(pickRandomFromList(Lists.MARITAL_STATUS_CHILDREN, 1, null).get(0));
				}
				p.setMotherTongue(pickRandomFromList(Lists.MOTHER_TONGUE, 1, null).get(0));
				// p.setPassport(randBool());
				String ph = pickRandomFromList(Lists.PHY_STATUS, 1, null).get(0);
				p.setPhysicalStatus(ph);
				if (!"Normal".equals(ph)) {
					p.setPhysicalStatusDetail(pickRandomFromList(Lists.PHY_STATUS_DETAIL, 1, null).get(0));
				}
				p.setSmoking(randBool());
				p.setAboutMe(randString());
				final String city = pickRandomFromList(Lists.CITIES, 1, null).get(0);
				City c1 = cities.get(city);
				p.setCurrGeoAddress(c1.city);
				p.setCurrLongitude(c1.lon);
				p.setCurrLatitude(c1.lat);
				p.setCurrCountry("IN");
				final String famcity = pickRandomFromList(Lists.CITIES, 1, null).get(0);
				c1 = cities.get(famcity);
				p.setFamGeoAddress(c1.city);
				p.setFamLongitude(c1.lon);
				p.setFamLatitude(c1.lat);
				profiles.add(p);
			}
			// System.out.println(p);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return profiles;
	}

	private class City {
		public String city;
		public Double lon;
		public Double lat;

		public City(String city, Double lon, Double lat) {
			this.city = city;
			this.lon = lon;
			this.lat = lat;
		}
	}

	Map<String, City> cities = new HashMap<String, City>();

	private void readXML() {
		List<String> cit = new ArrayList<String>();
		try {
			String str = "<?xml version=\"1.0\"?><gpx creator=\"GPS Visualizer http://www.gpsvisualizer.com/\" version=\"1.0\" xmlns=\"http://www.topografix.com/GPX/1/0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\"><wpt lat=\"19.0176147\" lon=\"72.8561644\">  <name>Mumbai,Maharashtra</name>  <desc>Mumbai, Maharashtra, India</desc></wpt><wpt lat=\"28.635308\" lon=\"77.22496\">  <name>Delhi,Delhi</name>  <desc>New Delhi, Delhi, India</desc></wpt><wpt lat=\"12.9715987\" lon=\"77.5945627\">  <name>Bangalore,Karnataka</name>  <desc>Bengaluru, Karnataka, India</desc></wpt><wpt lat=\"17.385044\" lon=\"78.486671\">  <name>Hyderabad,Andhra Pradesh</name>  <desc>Hyderabad, Andhra Pradesh, India</desc></wpt><wpt lat=\"23.0395677\" lon=\"72.5660045\">  <name>Ahmedabad,Gujarat</name>  <desc>Ahmedabad, Gujarat, India</desc></wpt><wpt lat=\"13.060422\" lon=\"80.249583\">  <name>Chennai,Tamil Nadu</name>  <desc>Chennai, Tamil Nadu, India</desc></wpt><wpt lat=\"22.572646\" lon=\"88.363895\">  <name>Kolkata,West Bengal</name>  <desc>Kolkata, West Bengal, India</desc></wpt><wpt lat=\"21.195\" lon=\"72.819444\">  <name>Surat,Gujarat</name>  <desc>Surat, Gujarat, India</desc></wpt><wpt lat=\"18.5204303\" lon=\"73.8567437\">  <name>Pune,Maharashtra</name>  <desc>Pune, Maharashtra, India</desc></wpt><wpt lat=\"26.917\" lon=\"75.817\">  <name>Jaipur,Rajasthan</name>  <desc>Jaipur, Rajasthan, India</desc></wpt><wpt lat=\"26.8465108\" lon=\"80.9466832\">  <name>Lucknow,Uttar Pradesh</name>  <desc>Lucknow, Uttar Pradesh, India</desc></wpt><wpt lat=\"26.449923\" lon=\"80.3318736\">  <name>Kanpur,Uttar Pradesh</name>  <desc>Kanpur, Uttar Pradesh, India</desc></wpt><wpt lat=\"21.1458004\" lon=\"79.0881546\">  <name>Nagpur,Maharashtra</name>  <desc>Nagpur, Maharashtra, India</desc></wpt><wpt lat=\"22.725313\" lon=\"75.865555\">  <name>Indore,Madhya Pradesh</name>  <desc>Indore, Madhya Pradesh, India</desc></wpt><wpt lat=\"19.23184\" lon=\"72.967178\">  <name>Thane,Maharashtra</name>  <desc>Thane, Maharashtra, India</desc></wpt><wpt lat=\"23.2599333\" lon=\"77.412615\">  <name>Bhopal,Madhya Pradesh</name>  <desc>Bhopal, Madhya Pradesh, India</desc></wpt><wpt lat=\"17.6868159\" lon=\"83.2184815\">  <name>Visakhapatnam,Andhra Pradesh</name>  <desc>Vishakhapatnam, Andhra Pradesh, India</desc></wpt><wpt lat=\"18.618679\" lon=\"73.803749\">  <name>Pimpri-Chinchwad,Maharashtra</name>  <desc>Pimpri Chinchwad, Maharashtra, India</desc></wpt><wpt lat=\"25.6125\" lon=\"85.1283333\">  <name>Patna,Bihar</name>  <desc>Patna, Bihar, India</desc></wpt><wpt lat=\"22.3073095\" lon=\"73.1810976\">  <name>Vadodara,Gujarat</name>  <desc>Vadodara, Gujarat, India</desc></wpt><wpt lat=\"28.6691565\" lon=\"77.4537578\">  <name>Ghaziabad,Uttar Pradesh</name>  <desc>Ghaziabad, Uttar Pradesh, India</desc></wpt><wpt lat=\"30.900965\" lon=\"75.8572758\">  <name>Ludhiana,Punjab</name>  <desc>Ludhiana, Punjab, India</desc></wpt><wpt lat=\"27.1766701\" lon=\"78.0080745\">  <name>Agra,Uttar Pradesh</name>  <desc>Agra, Uttar Pradesh, India</desc></wpt><wpt lat=\"19.9974533\" lon=\"73.7898023\">  <name>Nashik,Maharashtra</name>  <desc>Nashik, Maharashtra, India</desc></wpt><wpt lat=\"28.382219\" lon=\"77.303093\">  <name>Faridabad,Haryana</name>  <desc>Faridabad, Haryana, India</desc></wpt><wpt lat=\"28.9844618\" lon=\"77.7064137\">  <name>Meerut,Uttar Pradesh</name>  <desc>Meerut, Uttar Pradesh, India</desc></wpt><wpt lat=\"22.2985699\" lon=\"70.7943018\">  <name>Rajkot,Gujarat</name>  <desc>Rajkot, Gujarat, India</desc></wpt><wpt lat=\"19.25\" lon=\"73.13\">  <name>Kalyan-Dombivali,Maharashtra</name>  <desc>Kalyan-Dombivali, Maharashtra, India</desc></wpt><wpt lat=\"25.3176452\" lon=\"82.9739144\">  <name>Varanasi,Uttar Pradesh</name>  <desc>Varanasi, Uttar Pradesh, India</desc></wpt><wpt lat=\"34.0836581\" lon=\"74.7973681\">  <name>Srinagar,Jammu and Kashmir</name>  <desc>Srinagar</desc></wpt><wpt lat=\"19.8761653\" lon=\"75.3433139\">  <name>Aurangabad,Maharashtra</name>  <desc>Aurangabad, Maharashtra, India</desc></wpt><wpt lat=\"23.7956531\" lon=\"86.4303859\">  <name>Dhanbad,Jharkhand</name>  <desc>Dhanbad, Jharkhand, India</desc></wpt><wpt lat=\"31.6339793\" lon=\"74.8722642\">  <name>Amritsar,Punjab</name>  <desc>Amritsar, Punjab, India</desc></wpt><wpt lat=\"19.0330488\" lon=\"73.0296625\">  <name>Navi Mumbai,Maharashtra</name>  <desc>Navi Mumbai, Maharashtra, India</desc></wpt><wpt lat=\"25.4358011\" lon=\"81.846311\">  <name>Allahabad,Uttar Pradesh</name>  <desc>Allahabad, Uttar Pradesh, India</desc></wpt><wpt lat=\"23.3440997\" lon=\"85.309562\">  <name>Ranchi,Jharkhand</name>  <desc>Ranchi, Jharkhand, India</desc></wpt><wpt lat=\"22.5957689\" lon=\"88.2636394\">  <name>Howrah,West Bengal</name>  <desc>Howrah, West Bengal, India</desc></wpt><wpt lat=\"11.0168445\" lon=\"76.9558321\">  <name>Coimbatore,Tamil Nadu</name>  <desc>Coimbatore, Tamil Nadu, India</desc></wpt><wpt lat=\"23.165586\" lon=\"79.94303\">  <name>Jabalpur,Madhya Pradesh</name>  <desc>Jabalpur, Madhya Pradesh, India</desc></wpt><wpt lat=\"26.224447\" lon=\"78.178711\">  <name>Gwalior,Madhya Pradesh</name>  <desc>Gwalior, Madhya Pradesh, India</desc></wpt><wpt lat=\"16.5061743\" lon=\"80.6480153\">  <name>Vijayawada,Andhra Pradesh</name>  <desc>Vijayawada, Andhra Pradesh, India</desc></wpt><wpt lat=\"26.2567287\" lon=\"73.0170442\">  <name>Jodhpur,Rajasthan</name>  <desc>Jodhpur, Rajasthan, India</desc></wpt><wpt lat=\"9.9252007\" lon=\"78.1197754\">  <name>Madurai,Tamil Nadu</name>  <desc>Madurai, Tamil Nadu, India</desc></wpt><wpt lat=\"21.2513844\" lon=\"81.6296413\">  <name>Raipur,Chhattisgarh</name>  <desc>Raipur, Chhattisgarh, India</desc></wpt><wpt lat=\"25.1695114\" lon=\"75.8539898\">  <name>Kota,Rajasthan</name>  <desc>Kota, Rajasthan, India</desc></wpt><wpt lat=\"26.147129\" lon=\"91.7355511\">  <name>Guwahati,Assam</name>  <desc>Guwahati, Assam, India</desc></wpt><wpt lat=\"30.7333148\" lon=\"76.7794179\">  <name>Chandigarh,Chandigarh</name>  <desc>Chandigarh, India</desc></wpt><wpt lat=\"17.68\" lon=\"75.92\">  <name>Solapur,Maharashtra</name>  <desc>Solapur, Maharashtra, India</desc></wpt><wpt lat=\"15.34453\" lon=\"75.135277\">  <name>Hubballi-Dharwad,Karnataka</name>  <desc>Hubli, Karnataka, India</desc></wpt><wpt lat=\"28.3670355\" lon=\"79.4304381\">  <name>Bareilly,Uttar Pradesh</name>  <desc>Bareilly, Uttar Pradesh, India</desc></wpt><wpt lat=\"28.8315925\" lon=\"78.7782764\">  <name>Moradabad,Uttar Pradesh</name>  <desc>Moradabad, Uttar Pradesh, India</desc></wpt><wpt lat=\"12.303534\" lon=\"76.64611\">  <name>Mysore,Karnataka</name>  <desc>Mysore, Karnataka, India</desc></wpt><wpt lat=\"27.89381\" lon=\"78.068138\">  <name>Aligarh,Uttar Pradesh</name>  <desc>Aligarh, Uttar Pradesh, India</desc></wpt><wpt lat=\"31.3260152\" lon=\"75.5761829\">  <name>Jalandhar,Punjab</name>  <desc>Jalandhar, Punjab, India</desc></wpt><wpt lat=\"10.7904833\" lon=\"78.7046725\">  <name>Tiruchirappalli,Tamil Nadu</name>  <desc>Thiruchirapalli, Tamil Nadu, India</desc></wpt><wpt lat=\"20.2960587\" lon=\"85.8245398\">  <name>Bhubaneswar,Orissa</name>  <desc>Bhubaneswar, Orissa, India</desc></wpt><wpt lat=\"11.664325\" lon=\"78.1460142\">  <name>Salem,Tamil Nadu</name>  <desc>Salem, Tamil Nadu, India</desc></wpt><wpt lat=\"19.27883\" lon=\"72.878792\">  <name>Mira-Bhayandar,Maharashtra</name>  <desc>Mira Bhayandar, Maharashtra, India</desc></wpt><wpt lat=\"8.487495\" lon=\"76.948623\">  <name>Thiruvananthapuram,Kerala</name>  <desc>Trivandrum, Kerala, India</desc></wpt><wpt lat=\"19.2938306\" lon=\"73.0658389\">  <name>Bhiwandi,Maharashtra</name>  <desc>Bhiwandi, Maharashtra, India</desc></wpt><wpt lat=\"29.97\" lon=\"77.55\">  <name>Saharanpur,Uttar Pradesh</name>  <desc>Saharanpur, Uttar Pradesh, India</desc></wpt><wpt lat=\"26.75\" lon=\"83.3666667\">  <name>Gorakhpur,Uttar Pradesh</name>  <desc>Gorakhpur, Uttar Pradesh, India</desc></wpt><wpt lat=\"16.29851\" lon=\"80.433647\">  <name>Guntur,Andhra Pradesh</name>  <desc>Guntur, Andhra Pradesh, India</desc></wpt><wpt lat=\"28.01989\" lon=\"73.317551\">  <name>Bikaner,Rajasthan</name>  <desc>Bikaner, Rajasthan, India</desc></wpt><wpt lat=\"20.930679\" lon=\"77.758713\">  <name>Amravati,Maharashtra</name>  <desc>Amravati, Maharashtra, India</desc></wpt><wpt lat=\"28.57\" lon=\"77.32\">  <name>Noida,Uttar Pradesh</name>  <desc>NOIDA, Uttar Pradesh, India</desc></wpt><wpt lat=\"21.183008\" lon=\"81.361862\">  <name>Bhilai,Chhattisgarh</name>  <desc>Bhilai, Chhattisgarh, India</desc></wpt><wpt lat=\"22.77849\" lon=\"86.209\">  <name>Jamshedpur,Jharkhand</name>  <desc>Jamshedpur, Jharkhand, India</desc></wpt><wpt lat=\"18.000055\" lon=\"79.588167\">  <name>Warangal,Andhra Pradesh</name>  <desc>Warangal, Andhra Pradesh, India</desc></wpt><wpt lat=\"20.462123\" lon=\"85.881286\">  <name>Cuttack,Orissa</name>  <desc>Cuttack, Orissa, India</desc></wpt><wpt lat=\"27.1591006\" lon=\"78.3957574\">  <name>Firozabad,Uttar Pradesh</name>  <desc>Firozabad, Uttar Pradesh, India</desc></wpt><wpt lat=\"9.9457876\" lon=\"76.275443\">  <name>Kochi (Cochin),Kerala</name>  <desc>Kochi Naval Airport, Bristow Rd, Willingdon Island, Ernakulam, Kerala, India</desc></wpt><wpt lat=\"21.7644725\" lon=\"72.1519304\">  <name>Bhavnagar,Gujarat</name>  <desc>Bhavnagar, Gujarat, India</desc></wpt><wpt lat=\"30.3164945\" lon=\"78.0321918\">  <name>Dehradun,Uttarakhand</name>  <desc>Dehradun, Uttarakhand, India</desc></wpt><wpt lat=\"23.496531\" lon=\"87.324203\">  <name>Durgapur,West Bengal</name>  <desc>Durgapur, West Bengal, India</desc></wpt><wpt lat=\"23.68721\" lon=\"86.973343\">  <name>Asansol,West Bengal</name>  <desc>Asansol, West Bengal, India</desc></wpt><wpt lat=\"19.153061\" lon=\"77.305847\">  <name>Nanded,Maharashtra</name>  <desc>Nanded, Maharashtra, India</desc></wpt><wpt lat=\"16.7\" lon=\"74.2333\">  <name>Kolhapur,Maharashtra</name>  <desc>Kolhapur, Maharashtra, India</desc></wpt><wpt lat=\"26.45\" lon=\"74.64\">  <name>Ajmer,Rajasthan</name>  <desc>Ajmer, Rajasthan, India</desc></wpt><wpt lat=\"17.329731\" lon=\"76.8342957\">  <name>Gulbarga,Karnataka</name>  <desc>Gulbarga, Karnataka, India</desc></wpt><wpt lat=\"22.4666667\" lon=\"70.0666667\">  <name>Jamnagar,Gujarat</name>  <desc>Jamnagar, Gujarat, India</desc></wpt><wpt lat=\"23.177169\" lon=\"75.782888\">  <name>Ujjain,Madhya Pradesh</name>  <desc>Ujjain, Madhya Pradesh, India</desc></wpt><wpt lat=\"28.6869319\" lon=\"77.3832563\">  <name>Loni,Uttar Pradesh</name>  <desc>Loni Rd, Ghaziabad, Uttar Pradesh, India</desc></wpt><wpt lat=\"26.7077972\" lon=\"88.4274818\">  <name>Siliguri,West Bengal</name>  <desc>Siliguri, West Bengal, India</desc></wpt><wpt lat=\"25.444121\" lon=\"78.567604\">  <name>Jhansi,Uttar Pradesh</name>  <desc>Jhansi, Uttar Pradesh, India</desc></wpt><wpt lat=\"19.215829\" lon=\"73.154634\">  <name>Ulhasnagar,Maharashtra</name>  <desc>Ulhasnagar, Maharashtra, India</desc></wpt><wpt lat=\"14.4166667\" lon=\"79.9666667\">  <name>Nellore,Andhra Pradesh</name>  <desc>Nellore, Andhra Pradesh, India</desc></wpt><wpt lat=\"32.7266016\" lon=\"74.8570259\">  <name>Jammu,Jammu and Kashmir</name>  <desc>Jammu</desc></wpt><wpt lat=\"16.85438\" lon=\"74.564171\">  <name>Sangli-Miraj &amp; Kupwad,Maharashtra</name>  <desc>Sangli, Maharashtra, India</desc></wpt><wpt lat=\"15.85036\" lon=\"74.504669\">  <name>Belgaum,Karnataka</name>  <desc>Belgaum, Karnataka, India</desc></wpt><wpt lat=\"12.9141417\" lon=\"74.8559568\">  <name>Mangalore,Karnataka</name>  <desc>Mangalore, Karnataka, India</desc></wpt><wpt lat=\"13.1\" lon=\"80.16\">  <name>Ambattur,Tamil Nadu</name>  <desc>Ambattur, Tamil Nadu, India</desc></wpt><wpt lat=\"8.733\" lon=\"77.7\">  <name>Tirunelveli,Tamil Nadu</name>  <desc>Tirunelveli, Tamil Nadu, India</desc></wpt><wpt lat=\"20.5499359\" lon=\"74.528751\">  <name>Malegaon,Maharashtra</name>  <desc>Malegaon, Maharashtra, India</desc></wpt><wpt lat=\"24.7800113\" lon=\"84.9818234\">  <name>Gaya,Bihar</name>  <desc>Gaya, Bihar, India</desc></wpt><wpt lat=\"21.013321\" lon=\"75.563972\">  <name>Jalgaon,Maharashtra</name>  <desc>Jalgaon, Maharashtra, India</desc></wpt><wpt lat=\"24.57127\" lon=\"73.691544\">  <name>Udaipur,Rajasthan</name>  <desc>Udaipur, Rajasthan, India</desc></wpt><wpt lat=\"22.51\" lon=\"88.23\">  <name>Maheshtala,West Bengal</name>  <desc>Maheshtala, West Bengal, India</desc></wpt><wpt lat=\"11.098246\" lon=\"77.352695\">  <name>Tirupur,Tamil Nadu</name>  <desc>Tiruppur, Tamil Nadu, India</desc></wpt><wpt lat=\"14.45372\" lon=\"75.91893\">  <name>Davanagere,Karnataka</name>  <desc>Davanagere, Karnataka, India</desc></wpt><wpt lat=\"11.2554\" lon=\"75.781212\">  <name>Kozhikode (Calicut),Kerala</name>  <desc>Kozhikode, Kerala, India</desc></wpt><wpt lat=\"20.70388\" lon=\"76.997093\">  <name>Akola,Maharashtra</name>  <desc>Akola, Maharashtra, India</desc></wpt><wpt lat=\"15.8155688\" lon=\"78.0354453\">  <name>Kurnool,Andhra Pradesh</name>  <desc>Kurnool, Andhra Pradesh, India</desc></wpt><wpt lat=\"22.4415013\" lon=\"88.4326817\">  <name>Rajpur Sonarpur,West Bengal</name>  <desc>Sonarpur Flyover, Sonarpur, Kolkata, West Bengal, India</desc></wpt><wpt lat=\"23.7606657\" lon=\"86.0529604\">  <name>Bokaro,Jharkhand</name>  <desc>Bokaro, Jharkhand, India</desc></wpt><wpt lat=\"22.61\" lon=\"88.41\">  <name>South Dumdum,West Bengal</name>  <desc>South Dum Dum, West Bengal, India</desc></wpt><wpt lat=\"15.13854\" lon=\"76.918732\">  <name>Bellary,Karnataka</name>  <desc>Bellary, Karnataka, India</desc></wpt><wpt lat=\"30.33\" lon=\"76.4\">  <name>Patiala,Punjab</name>  <desc>Patiala, Punjab, India</desc></wpt><wpt lat=\"23.5006421\" lon=\"87.3984365\">  <name>Gopalpur,West Bengal</name>  <desc>Gopalpur, West Bengal, India</desc></wpt><wpt lat=\"25.24003\" lon=\"86.984512\">  <name>Bhagalpur,Bihar</name>  <desc>Bhagalpur, Bihar, India</desc></wpt><wpt lat=\"13.3422222\" lon=\"77.1016667\">  <name>Tumakuru (Tumkur),Karnataka</name>  <desc>Tumkur, Karnataka, India</desc></wpt><wpt lat=\"29.4726817\" lon=\"77.7085091\">  <name>Muzaffarnagar,Uttar Pradesh</name>  <desc>Muzaffarnagar, Uttar Pradesh, India</desc></wpt><wpt lat=\"23.5155347\" lon=\"88.5492813\">  <name>Bhatpara,West Bengal</name>  <desc>Chapra, West Bengal, India</desc></wpt><wpt lat=\"22.6959606\" lon=\"88.3966726\">  <name>Panihati,West Bengal</name>  <desc>Panihati College, Barasat Rd, Kolkata, West Bengal, India</desc></wpt><wpt lat=\"18.39768\" lon=\"76.580971\">  <name>Latur,Maharashtra</name>  <desc>Latur, Maharashtra, India</desc></wpt><wpt lat=\"20.901951\" lon=\"74.770866\">  <name>Dhule,Maharashtra</name>  <desc>Dhule, Maharashtra, India</desc></wpt><wpt lat=\"28.892361\" lon=\"76.59124\">  <name>Rohtak,Haryana</name>  <desc>Rohtak, Haryana, India</desc></wpt><wpt lat=\"22.35\" lon=\"82.75\">  <name>Korba,Chhattisgarh</name>  <desc>Korba, Chhattisgarh, India</desc></wpt><wpt lat=\"25.346251\" lon=\"74.636383\">  <name>Bhilwara,Rajasthan</name>  <desc>Bhilwara, Rajasthan, India</desc></wpt><wpt lat=\"19.308531\" lon=\"84.809647\">  <name>Brahmapur,Orissa</name>  <desc>Berhampur, Orissa, India</desc></wpt><wpt lat=\"26.122619\" lon=\"85.379969\">  <name>Muzaffarpur,Bihar</name>  <desc>Muzaffarpur, Bihar, India</desc></wpt><wpt lat=\"19.0952075\" lon=\"74.7495916\">  <name>Ahmadnagar,Maharashtra</name>  <desc>Ahmednagar, Maharashtra, India</desc></wpt><wpt lat=\"27.4924134\" lon=\"77.673673\">  <name>Mathura,Uttar Pradesh</name>  <desc>Mathura, Uttar Pradesh, India</desc></wpt><wpt lat=\"8.88119\" lon=\"76.6369097\">  <name>Kollam (Quilon),Kerala</name>  <desc>Kollam, Kerala, India</desc></wpt><wpt lat=\"13.12\" lon=\"80.1\">  <name>Avadi,Tamil Nadu</name>  <desc>Avadi, Tamil Nadu, India</desc></wpt><wpt lat=\"17.0005383\" lon=\"81.8040345\">  <name>Rajahmundry,Andhra Pradesh</name>  <desc>Rajahmundry, Andhra Pradesh, India</desc></wpt><wpt lat=\"22.6764908\" lon=\"88.3675634\">  <name>Kamarhati,West Bengal</name>  <desc>Kamarhati Masjid, Kolkata, West Bengal, India</desc></wpt><wpt lat=\"22.0796251\" lon=\"82.1391412\">  <name>Bilaspur,Chhattisgarh</name>  <desc>Bilaspur, Chhattisgarh, India</desc></wpt><wpt lat=\"27.88\" lon=\"79.92\">  <name>Shahjahanpur,Uttar Pradesh</name>  <desc>Shahjahanpur, Uttar Pradesh, India</desc></wpt><wpt lat=\"16.82402\" lon=\"75.71534\">  <name>Bijapur,Karnataka</name>  <desc>Bijapur, Karnataka, India</desc></wpt><wpt lat=\"28.802957\" lon=\"79.025444\">  <name>Rampur,Uttar Pradesh</name>  <desc>Rampur, Uttar Pradesh, India</desc></wpt><wpt lat=\"13.92225\" lon=\"75.570374\">  <name>Shivamogga (Shimoga),Karnataka</name>  <desc>Shimoga, Karnataka, India</desc></wpt><wpt lat=\"19.95\" lon=\"79.3\">  <name>Chandrapur,Maharashtra</name>  <desc>Chandrapur, Maharashtra, India</desc></wpt><wpt lat=\"10.5230675\" lon=\"76.2222106\">  <name>Thrissur,Kerala</name>  <desc>Thrissur, Kerala, India</desc></wpt><wpt lat=\"27.5618\" lon=\"76.608742\">  <name>Alwar,Rajasthan</name>  <desc>Alwar, Rajasthan, India</desc></wpt><wpt lat=\"23.2383\" lon=\"87.8608\">  <name>Bardhaman,West Bengal</name>  <desc>Bardhaman, West Bengal, India</desc></wpt><wpt lat=\"23.736975\" lon=\"86.838572\">  <name>Kulti,West Bengal</name>  <desc>Kulti, West Bengal, India</desc></wpt><wpt lat=\"16.945181\" lon=\"82.238647\">  <name>Kakinada,Andhra Pradesh</name>  <desc>Kakinada, Andhra Pradesh, India</desc></wpt><wpt lat=\"18.6725047\" lon=\"78.0940867\">  <name>Nizamabad,Andhra Pradesh</name>  <desc>Nizamabad, Andhra Pradesh, India</desc></wpt><wpt lat=\"19.25779\" lon=\"76.773743\">  <name>Parbhani,Maharashtra</name>  <desc>Parbhani, Maharashtra, India</desc></wpt><wpt lat=\"29.15307\" lon=\"75.718567\">  <name>Hisar,Haryana</name>  <desc>Hisar, Haryana, India</desc></wpt><wpt lat=\"11.9264416\" lon=\"79.789922\">  <name>Ozhukarai,Puducherry</name>  <desc>Ozhukarai Government School, Oulgaret, Puducherry, Pondicherry, India</desc></wpt><wpt lat=\"25.198009\" lon=\"85.521896\">  <name>Bihar Sharif,Bihar</name>  <desc>Bihar Sharif, Bihar, India</desc></wpt><wpt lat=\"29.39\" lon=\"76.97\">  <name>Panipat,Haryana</name>  <desc>Panipat, Haryana, India</desc></wpt><wpt lat=\"26.17\" lon=\"85.9\">  <name>Darbhanga,Bihar</name>  <desc>Darbhanga, Bihar, India</desc></wpt><wpt lat=\"22.645734\" lon=\"88.34786\">  <name>Bally,West Bengal</name>  <desc>Bally, Howrah, West Bengal, India</desc></wpt><wpt lat=\"23.727107\" lon=\"92.7176389\">  <name>Aizawl,Mizoram</name>  <desc>Aizawl, Mizoram, India</desc></wpt><wpt lat=\"22.961227\" lon=\"76.051411\">  <name>Dewas,Madhya Pradesh</name>  <desc>Dewas, Madhya Pradesh, India</desc></wpt><wpt lat=\"16.7\" lon=\"74.47\">  <name>Ichalkaranji,Maharashtra</name>  <desc>Ichalkaranji, Maharashtra, India</desc></wpt><wpt lat=\"13.65\" lon=\"79.4166667\">  <name>Tirupati,Andhra Pradesh</name>  <desc>Tirupati, Andhra Pradesh, India</desc></wpt><wpt lat=\"30.210994\" lon=\"74.9454745\">  <name>Bathinda,Punjab</name>  <desc>Bathinda, Punjab, India</desc></wpt><wpt lat=\"19.838949\" lon=\"75.887177\">  <name>Jalna,Maharashtra</name>  <desc>Jalna, Maharashtra, India</desc></wpt><wpt lat=\"25.78\" lon=\"87.47\">  <name>Purnia,Bihar</name>  <desc>Purnia, Bihar, India</desc></wpt><wpt lat=\"24.58\" lon=\"80.83\">  <name>Satna,Madhya Pradesh</name>  <desc>Satna, Madhya Pradesh, India</desc></wpt><wpt lat=\"25.94174\" lon=\"83.562042\">  <name>Mau,Uttar Pradesh</name>  <desc>Mau, Uttar Pradesh, India</desc></wpt><wpt lat=\"28.990703\" lon=\"77.015918\">  <name>Sonipat,Haryana</name>  <desc>Sonepat, Haryana, India</desc></wpt><wpt lat=\"27.4\" lon=\"79.5666667\">  <name>Farrukhabad,Uttar Pradesh</name>  <desc>Farrukhabad, Uttar Pradesh, India</desc></wpt><wpt lat=\"23.832294\" lon=\"78.744917\">  <name>Sagar,Madhya Pradesh</name>  <desc>Sagar, Madhya Pradesh, India</desc></wpt><wpt lat=\"21.189367\" lon=\"81.283039\">  <name>Durg,Chhattisgarh</name>  <desc>Durg, Chhattisgarh, India</desc></wpt><wpt lat=\"24.806299\" lon=\"93.948197\">  <name>Imphal,Manipur</name>  <desc>Imphal, Manipur, India</desc></wpt><wpt lat=\"23.330412\" lon=\"75.044315\">  <name>Ratlam,Madhya Pradesh</name>  <desc>Ratlam, Madhya Pradesh, India</desc></wpt><wpt lat=\"28.727249\" lon=\"77.779999\">  <name>Hapur,Uttar Pradesh</name>  <desc>Hapur, Uttar Pradesh, India</desc></wpt><wpt lat=\"14.6707094\" lon=\"77.5907443\">  <name>Anantapur,Andhra Pradesh</name>  <desc>Anantapur, Andhra Pradesh, India</desc></wpt><wpt lat=\"25.558797\" lon=\"84.667097\">  <name>Arrah,Bihar</name>  <desc>Arrah, Bihar, India</desc></wpt><wpt lat=\"18.4385553\" lon=\"79.1288412\">  <name>Karimnagar,Andhra Pradesh</name>  <desc>Karimnagar, Andhra Pradesh, India</desc></wpt><wpt lat=\"26.7833333\" lon=\"79.0166667\">  <name>Etawah,Uttar Pradesh</name>  <desc>Etawah, Uttar Pradesh, India</desc></wpt><wpt lat=\"19.195499\" lon=\"73.1939612\">  <name>Ambernath,Maharashtra</name>  <desc>Ambarnath, Maharashtra, India</desc></wpt><wpt lat=\"22.64\" lon=\"88.41\">  <name>North Dumdum,West Bengal</name>  <desc>North Dum Dum, West Bengal, India</desc></wpt><wpt lat=\"27.215599\" lon=\"77.49015\">  <name>Bharatpur,Rajasthan</name>  <desc>Bharatpur, Rajasthan, India</desc></wpt><wpt lat=\"28.635308\" lon=\"77.22496\">  <name>New Delhi,Delhi</name>  <desc>New Delhi, Delhi, India</desc></wpt><wpt lat=\"22.640368\" lon=\"88.372043\">  <name>Baranagar,West Bengal</name>  <desc>Baranagar, West Bengal, India</desc></wpt><wpt lat=\"13.16\" lon=\"80.3\">  <name>Tiruvottiyur,Tamil Nadu</name>  <desc>Tiruvottiyur, Chennai, Tamil Nadu, India</desc></wpt><wpt lat=\"24.53\" lon=\"81.3\">  <name>Rewa,Madhya Pradesh</name>  <desc>Rewa, Madhya Pradesh, India</desc></wpt><wpt lat=\"25.146621\" lon=\"82.562414\">  <name>Mirzapur,Uttar Pradesh</name>  <desc>Mirzapur, Uttar Pradesh, India</desc></wpt><wpt lat=\"16.20702\" lon=\"77.354362\">  <name>Raichur,Karnataka</name>  <desc>Raichur, Karnataka, India</desc></wpt><wpt lat=\"25.771151\" lon=\"73.323174\">  <name>Pali,Rajasthan</name>  <desc>Pali, Rajasthan, India</desc></wpt><wpt lat=\"18.76116\" lon=\"79.408139\">  <name>Ramagundam,Andhra Pradesh</name>  <desc>Ramagundam, Andhra Pradesh, India</desc></wpt><wpt lat=\"29.92\" lon=\"73.88\">  <name>Sri Ganganagar,Rajasthan</name>  <desc>Sri Ganganagar, Rajasthan, India</desc></wpt><wpt lat=\"22.4744363\" lon=\"88.1000377\">  <name>Uluberia,West Bengal</name>  <desc>Uluberia, West Bengal, India</desc></wpt><wpt lat=\"22.8567696\" lon=\"88.5333574\">  <name>Naihati,West Bengal</name>  <desc>Naihati-Habra Rd, West Bengal, India</desc></wpt><wpt lat=\"24.1992101\" lon=\"82.6645469\">  <name>Singrauli,Madhya Pradesh</name>  <desc>Singrauli, Madhya Pradesh, India</desc></wpt><wpt lat=\"26.494137\" lon=\"88.2388162\">  <name>Bidhan Nagar,West Bengal</name>  <desc>Bidhan Nagar, West Bengal, India</desc></wpt><wpt lat=\"17.90737\" lon=\"77.527138\">  <name>Bidar,Karnataka</name>  <desc>Bidar, Karnataka, India</desc></wpt><wpt lat=\"23.229391\" lon=\"72.651974\">  <name>Gandhinagar,Gujarat</name>  <desc>Gandhinagar, Gujarat, India</desc></wpt><wpt lat=\"15.2688542\" lon=\"76.3909241\">  <name>Hosapete,Karnataka</name>  <desc>Hospet, Karnataka, India</desc></wpt><wpt lat=\"28.6793759\" lon=\"77.069398\">  <name>Nangloi Jat,Delhi</name>  <desc>Nangloi Jat, New Delhi, Delhi, India</desc></wpt><wpt lat=\"22.95\" lon=\"88.02\">  <name>Srirampur,West Bengal</name>  <desc>Srirampur, West Bengal, India</desc></wpt><wpt lat=\"18.991029\" lon=\"73.108306\">  <name>Panvel,Maharashtra</name>  <desc>Panvel, Maharashtra, India</desc></wpt><wpt lat=\"30.6799468\" lon=\"76.7221082\">  <name>Mohali,Punjab</name>  <desc>Sahibzada Ajit Singh Nagar, Punjab, India</desc></wpt></gpx>";

			DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
			DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
			// Document doc = docBuilder.parse(new File("./1319923574-27686.gpx"));
			Document doc = docBuilder.parse(new ByteArrayInputStream(str.getBytes()));
			doc.getDocumentElement().normalize();
			NodeList listOfAddresses = doc.getElementsByTagName("wpt");
			// int totalAddresses = listOfAddresses.getLength();
			for (int s = 0; s < listOfAddresses.getLength(); s++) {

				Node wptNode = listOfAddresses.item(s);
				if (wptNode.getNodeType() == Node.ELEMENT_NODE) {

					Element wptElement = (Element) wptNode;
					String lon = wptElement.getAttribute("lon");
					String lat = wptElement.getAttribute("lat");
					NodeList descList = wptElement.getElementsByTagName("desc");
					Element descElement = (Element) descList.item(0);
					String city = ((Node) descElement.getFirstChild()).getNodeValue().trim();
					cities.put(city, new City(city, Double.parseDouble(lon), Double.parseDouble(lat)));
					cit.add(city);
					System.out.println("lon : " + lon);
					System.out.println("lat : " + lat);
					System.out.println("desc : " + ((Node) descElement.getFirstChild()).getNodeValue().trim());
				}

			}
			Map<String, List<String>> c = new HashMap<String, List<String>>();
			c.put("", cit);
			ConstantsManager.getInstance().getLists().put(Lists.CITIES, c);

		} catch (SAXParseException err) {
			System.out.println("** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId());
			System.out.println(" " + err.getMessage());

		} catch (SAXException e) {
			Exception x = e.getException();
			((x == null) ? e : x).printStackTrace();

		} catch (Throwable t) {
			t.printStackTrace();
		}
		// System.exit (0);

	}// end of main

	private long ftInStringToInches(String ft) {
		String[] feet = ft.split("\\D");
		long feetInt = Long.parseLong(feet[0]);
		long inInt = feetInt * 12;
		for (int i = 1; i < feet.length; i++) {
			if (!"".equals(feet[i])) {
				inInt += Long.parseLong(feet[i]);
				break;
			}
		}
		return inInt;
	}

	private String randString() {
		return "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas consectetur fringilla orci sed vehicula. Morbi velit eros, vestibulum ut pharetra ut, porta ullamcorper nunc. Cras tempor sollicitudin lacus, non mollis lectus auctor eget. Nam at enim sodales eros facilisis consequat nec a nibh. Etiam laoreet tempor purus, id vehicula risus ullamcorper ac. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Cras id venenatis purus.";
	}

	private String randBool() {
		double d = Math.random();
		return d < .5 ? "Yes" : "No";
	}

	private List<String> pickRandomFromList(Lists type, int max, String dependency) {
		Map<String, List<String>> list = ConstantsManager.getInstance().getLists().get(type);
		List<String> vals = new ArrayList<String>();
		if (list.size() == 1) { // single grouped
			if (type == Lists.CASTE) {
				vals.addAll(list.get(dependency));
			} else {
				vals.addAll(list.get(""));
			}

		} else {
			if (type == Lists.CASTE) {
				vals.addAll(list.get(dependency));
			} else {
				for (List<String> v : list.values()) {
					vals.addAll(v);
				}
			}
		}

		Set<String> pickedVals = new HashSet<String>();
		for (int i = 0; i < max; i++) {
			int pos = (int) (Math.random() * vals.size());
			// System.out.println("List: " + vals + ", pos= " + pos);
			pickedVals.add(vals.get(pos));
		}
		List<String> a = new ArrayList<String>();
		a.addAll(pickedVals);
		return a;
	}
}
